<#include "macro_.ftl">
package ${packageCode}.${moduleMapperKey}.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.val;

import org.apache.commons.lang3.StringUtils;

import com.fand.dto.PaginationDto;
import com.fand.persistent.builder.ModelArgs;
import com.fand.persistent.builder.ModelBuilder;
import com.fand.persistent.builder.ModelBuilderUtils;
import com.fand.persistent.support.DaoJdbcSupport;
<#list poMapperList as poMapper>
import ${packageCode}.${moduleMapperKey}.dto.${poMapper.code}Dto;
</#list>

/**
 * ${businessMapper.name!businessCode}
 *
 * @author ${author!'yaoHT'}
 * 
 */
public class ${businessCode}JdbcDao extends DaoJdbcSupport implements ${businessCode}Dao {
<#list poMapperList as poMapper>

	@Override
	public int insert${poMapper.code}By1(${poMapper.code}Dto insert${poMapper.code}, String... insertProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insert${poMapper.code}, insertProperties));
		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/insert${poMapper.code}By1", modelBuilder.build());
	}
<#if poMapper.markService>

	@Override
	public int insert${poMapper.code}By1_1(${poMapper.code}Dto insert${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insert${poMapper.code}));
				
		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/insert${poMapper.code}By1", modelBuilder.build());
	}

	@Override
	public int insert${poMapper.code}By2(${poMapper.code}Dto insert${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.INSERT,
				insert${poMapper.code}));

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/insert${poMapper.code}By2", modelBuilder.build());
	}
</#if>

	@Override
	public int delete${poMapper.code}By1(${poMapper.code}Dto delete${poMapper.code}, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(delete${poMapper.code},
				whereEqProperties));

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/delete${poMapper.code}By1", modelBuilder.build());
	}
<#if poMapper.markService>
	@Override
	public int delete${poMapper.code}By1_1(${poMapper.code}Dto delete${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(delete${poMapper.code}));

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/delete${poMapper.code}By1", modelBuilder.build());
	}
	
	@Override
	public int delete${poMapper.code}ByIds(${poMapper.code}Dto delete${poMapper.code}) {
		val model = new HashMap<String, Object>();

		model.put("IDS", delete${poMapper.code}.getIds());

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/delete${poMapper.code}ByIds", model);
	}
</#if>

	@Override
	public int update${poMapper.code}By1(${poMapper.code}Dto update${poMapper.code}, String[] updateProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(ModelBuilder.UPDATE,
				update${poMapper.code}, updateProperties), new ModelArgs(update${poMapper.code}, whereEqProperties));

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/update${poMapper.code}By1", modelBuilder.build());
	}
<#if poMapper.markService>

	@Override
	public int update${poMapper.code}By1_1(${poMapper.code}Dto update${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(update${poMapper.code}));

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/update${poMapper.code}By1", modelBuilder.build());
	}
	
	@Override
	public int update${poMapper.code}By2(${poMapper.code}Dto update${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(update${poMapper.code}));

		return this.update("${moduleMapperKey}/${poMapper.code?uncap_first}/update${poMapper.code}By2", modelBuilder.build());
	}
</#if>

	@Override
	public <R> R select${poMapper.code}By1ForObject(Class<R> requiredType, ${poMapper.code}Dto select${poMapper.code}, String objectId,
			String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code},
				whereEqProperties));

		return this.selectForObject(requiredType, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject", objectId,
				modelBuilder.build());
	}
<#if poMapper.markService>

	@Override
	public <R> R select${poMapper.code}By1_1ForObject(Class<R> requiredType, ${poMapper.code}Dto select${poMapper.code}, String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForObject(requiredType, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> R select${poMapper.code}By2ForObject(Class<R> requiredType, ${poMapper.code}Dto select${poMapper.code}, String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForObject(requiredType, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By2ForObject", objectId,
				modelBuilder.build());
	}
</#if>

	@Override
	public <R> List<R> select${poMapper.code}By1ForObjectList(Class<R> requiredType, ${poMapper.code}Dto select${poMapper.code}, String objectId,
			String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code},
				whereEqProperties));

		return this.selectForObjectList(requiredType, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject", objectId,
				modelBuilder.build());
	}
<#if poMapper.markService>

	@Override
	public <R> List<R> select${poMapper.code}By1_1ForObjectList(Class<R> requiredType, ${poMapper.code}Dto select${poMapper.code}, String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForObjectList(requiredType, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject", objectId,
				modelBuilder.build());
	}

	@Override
	public <R> List<R> select${poMapper.code}By2ForObjectList(Class<R> requiredType, ${poMapper.code}Dto select${poMapper.code}, String objectId) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForObjectList(requiredType, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By2ForObject", objectId,
				modelBuilder.build());
	}
</#if>

	@Override
	public <R> R select${poMapper.code}By1ForMappedObject(Class<R> mappedClass, ${poMapper.code}Dto select${poMapper.code},
			String[] selectProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code},
				whereEqProperties));

		modelBuilder.putTrueExtend(ModelBuilder.SELECT, selectProperties);

		return this.selectForMappedObject(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForMappedObjectList",
				modelBuilder.build());
	}
<#if poMapper.markService>

	@Override
	public <R> R select${poMapper.code}By1_1ForMappedObject(Class<R> mappedClass, ${poMapper.code}Dto select${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForMappedObject(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForMappedObjectList",
				modelBuilder.build());
	}

	@Override
	public <R> R select${poMapper.code}By2ForMappedObject(Class<R> mappedClass, ${poMapper.code}Dto select${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForMappedObject(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By2ForMappedObjectList",
				modelBuilder.build());
	}

	@Override
	public int select${poMapper.code}ByCodeNqIdForInteger(${poMapper.code}Dto select${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder();

//		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder().putExtend(null, "code", null,
//				select${poMapper.code}.getCode());

//		if (StringUtils.isNotBlank(select${poMapper.code}.getId())) {
//			modelBuilder.putExtend(ModelBuilder.WHERE__AND__NQ, "id", null, select${poMapper.code}.getId());
//		}

		return this.selectForObject(Integer.class, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject", null,
				modelBuilder.build());
	}
</#if>

	@Override
	public <R> List<R> select${poMapper.code}By1ForMappedObjectList(Class<R> mappedClass, ${poMapper.code}Dto select${poMapper.code},
			String[] selectProperties, String... whereEqProperties) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code},
				whereEqProperties));

		modelBuilder.putTrueExtend(ModelBuilder.SELECT, selectProperties);

		return this.selectForMappedObjectList(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForMappedObjectList",
				modelBuilder.build());
	}
<#if poMapper.markService>

	@Override
	public <R> List<R> select${poMapper.code}By1_1ForMappedObjectList(Class<R> mappedClass, ${poMapper.code}Dto select${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForMappedObjectList(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForMappedObjectList",
				modelBuilder.build());
	}

	@Override
	public <R> List<R> select${poMapper.code}By2ForMappedObjectList(Class<R> mappedClass, ${poMapper.code}Dto select${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(select${poMapper.code}));

		return this.selectForMappedObjectList(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By2ForMappedObjectList",
				modelBuilder.build());
	}

	@Override
	public <R> PaginationDto<R> pagination${poMapper.code}By1ForMappedObjectList(Class<R> mappedClass,
				${poMapper.code}Dto pagination${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(pagination${poMapper.code}));

		return this.paginationForMappedObjectList(mappedClass, "${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject",
				"${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForMappedObjectList",
				pagination${poMapper.code}.getPaginationNo(),
				pagination${poMapper.code}.getPaginationSize(),
				modelBuilder.build());
	}

	@Override
	public PaginationDto<Map<String, Object>> pagination${poMapper.code}By1ForMapList(${poMapper.code}Dto pagination${poMapper.code}) {
		final ModelBuilder modelBuilder = ModelBuilderUtils.newModelBuilder(new ModelArgs(pagination${poMapper.code}));

		return this.paginationForMapList("${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForObject",
				"${moduleMapperKey}/${poMapper.code?uncap_first}/select${poMapper.code}By1ForMappedObjectList",
				pagination${poMapper.code}.getPaginationNo(),
				pagination${poMapper.code}.getPaginationSize(),
				modelBuilder.build());
	}
</#if>
</#list>
}